<?php
    echo " Welcome to SK..!!!!"."</br>";
    
    require "policy.php";
        
    webcrawl();
    
    function webcrawl(){
    
        
        
        $link = array();
        $link[0] = "http://www.webucator.com/";
        $link[1] = "https://www.coursera.org/";
        $link[2] = "http://marakana.com/";
        $link[3] = "http://www.learningtree.com/";
        $link[4] = "http://en.wikipedia.org/wiki/List_of_programming_languages";
        
        
        foreach($link as $url){
            
            
            $html = file_get_contents($url);
            $dom_object = new DOMDocument();
            @$dom_object->loadHTML($html);
            $xpath_node = new DOMXPath($dom_object);
            $hrefs_links = $xpath_node->evaluate("/html/body//a");
            $nested_url = array();
            
            for ($count = 0; $count < $hrefs_links->length; $count++) {
                $href = $hrefs_links->item($count);
                $url_name = $href->getAttribute('href');
                $nested_url[] = $url_name;
                
            }
        
            $good_urls = preg_grep( "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $nested_url);
            
            //echo $print_array;
            
            //$good_urls = array_splice($good_urls,20,20);
            
            //$print_array = implode ( "</br>", $good_urls);
           // echo $print_array;
            
            
            $courseSelected = "java";
            
            foreach ( $good_urls as $url){
                
                if ((validate($url,$courseSelected))==true){
                    
                    echo $url."</br>";
                }
                

            }
            
            
        }
        
    }
    
            
            
            
            
           
    
            
            
            
            
            
            

            
        
    
    
    
?>
        

